package org.ljy;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.TimeZone;

public class logTimestampTest {

    public static long logTimeToTimestamp(String logTime) throws ParseException {
        // 定义日志时间格式（注意逗号分隔毫秒）
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS");
        // 若日志时间包含时区，需指定（如UTC或本地时区）
        sdf.setTimeZone(TimeZone.getDefault()); // 或TimeZone.getTimeZone("UTC")
        Date date = sdf.parse(logTime);
        return date.getTime(); // 返回与IOPoint.TIMESTAMP一致的毫秒级时间戳
    }

    // 将毫秒级时间戳转换为日志时间字符串
    public static String timestampToLogTime(long timestamp) {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS");
        sdf.setTimeZone(TimeZone.getDefault()); // 与日志时区保持一致
        return sdf.format(new Date(timestamp));
    }

    public static void main(String[] args) throws ParseException {
// 假设从日志中提取的时间
        String logTime = "2025-09-04 17:35:15,857";
        long logTimestamp = logTimeToTimestamp(logTime);
        System.out.println("日志时间对应的时间戳：" + logTimestamp);

        long Timestamp = 1761635078658L;
        String logTime1 = timestampToLogTime(Timestamp);
        System.out.println("时间戳对应日志时间："+logTime1);

        String role = "C1ZK1:LOOKING";
        String[] roleSegments = role.split(":");
        String role1 = roleSegments[roleSegments.length-1];
        System.out.println(role1);

    }
}
